package org.wangnian;

import org.springframework.core.io.support.SpringFactoriesLoader;
import org.wangnian.service.IFanCoreService;
import org.wangnian.service.impl.AaTypeFanServiceImpl;

import java.util.List;

public class Main {

    public static final String B_TYPE = "B";

    public static void main(String[] args) {
        turnOn(B_TYPE);
    }

    public static void turnOn(String type){
        // Spring SPI 使用 SpringFactoriesLoader 去发现并加载实现类
        // 本质就是读取配置文件的内容 并通过反射创建对象
        List<IFanCoreService> iFanCoreServices = SpringFactoriesLoader.loadFactories(IFanCoreService.class, Main.class.getClassLoader());
        for (IFanCoreService iFanCoreService : iFanCoreServices) {
            System.out.println("检测到的类名：" + iFanCoreService.getClass().getName() + ":" +iFanCoreService);
            // 判断是否是 B 型号的风扇，是的话直接开启
            if (B_TYPE.equals(iFanCoreService.getType())){
                iFanCoreService.turnOnOff();
            }
        }
    }


}
